/**
 * Dashboard to show the report
 */
Ext.define('Cps.controller.Dashboard', {
	requires: [ 'Cps.view.dashboard.ReportV2'],
    extend: 'Ext.app.Controller',

    views: [
        'Cps.view.dashboard.Dashboard'
    ],
    
    stores: ['Groups'],
    models: ['Cps.model.Company'],
    
    refs: [
         { ref: 'groups', selector: '#lstGroup' },
         { ref: 'resultPanel', selector: '#resultCtn' }
    ],
    
    /**
     * Init the controller
     */
    init: function() {
    	this.control({
    		'dashboard button[action=report]': {
    			click: this.onReport
    		}
    	});
    },
    
    onLaunch: function() {
    },

    onReport: function(button) {
		var form = button.up('form');
		var values = {};
		values.companies = Ext.getCmp('companies').getValue();
        values.account = Ext.getCmp('account').getValue();
        values.value1 = Ext.getCmp('value1').checked;
        values.value2 = Ext.getCmp('value2').checked;
        values.date_value = Ext.getCmp('date_value').getValue();
        values.date_trade = Ext.getCmp('date_trade').getValue();
        values.centralaccount = Ext.getCmp('centralaccount').checked;
        values.group = Ext.getCmp('group').getValue();

        if(values.date_value)
            values.date_value = Ext.util.Format.date(values.date_value, 'Ymd');
        if(values.date_trade)
            values.date_trade = Ext.util.Format.date(values.date_trade, 'Ymd');

		if(form.isValid()) {
            var store = Ext.create('Cps.view.dashboard.ReportV2', {
                params: values,
                panel: this.getResultPanel()
            });
            store.loadData();
			window.showingReport = 1;
		} else {
			Ext.Msg.show({ title: 'Error', msg: 'Invalid filter' });
		}
    }
});